package hos.ui;

import android.content.res.TypedArray;
import android.widget.LinearLayout;

import hos.ui.inter.OnClickableListener;
import hos.ui.item.ItemRadioLayout;
import hos.ui.radio.RadioGroupExtend;

/**
 * <p>Title: ItemViewUtils </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-04-18 13:53
 */
public class ItemViewUtils {
    private ItemViewUtils() {
    }

    public static void setOnCheckedListener(RadioGroupExtend.OnCheckedListener listener, ItemRadioLayout... itemRadioLayouts) {
        if (itemRadioLayouts == null) {
            return;
        }
        for (ItemRadioLayout itemRadioLayout : itemRadioLayouts) {
            itemRadioLayout.setOnCheckedListener(listener);
        }
    }

    public static void setOnCheckedListener(RadioGroupExtend.OnCheckedListener listener, RadioGroupExtend... itemRadioLayouts) {
        if (itemRadioLayouts == null) {
            return;
        }
        for (RadioGroupExtend itemRadioLayout : itemRadioLayouts) {
            itemRadioLayout.setOnCheckedListener(listener);
        }
    }

    public static int getLayoutParam(TypedArray typedArray, int styleable) {
        return getLayoutParam(typedArray, styleable, 0);
    }

    public static int getLayoutParam(TypedArray typedArray, int styleable, int defValue) {
        int enumOrDimen = 0;
        try {
            enumOrDimen = typedArray.getInt(styleable, defValue);
            if (enumOrDimen != LinearLayout.LayoutParams.MATCH_PARENT && enumOrDimen != LinearLayout.LayoutParams.WRAP_CONTENT) {
                enumOrDimen = typedArray.getDimensionPixelOffset(styleable, 0);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            enumOrDimen = typedArray.getDimensionPixelOffset(styleable, 0);
        }
        return enumOrDimen;
    }


    public static final void clickable(boolean isClickable, OnClickableListener... listeners) {
        for (OnClickableListener view : listeners) {
            if (view != null) {
                view.clickable(isClickable);
            }
        }
    }
}
